<?php
class ArticleHelper
{
	public static function patch(&$list, $single=false)
	{
		static $u = array();
		
		if($single)
		{
			$aid	=	isset($list['aid'])?$list['aid']:$list['model_id'];
			if(isset($u[$aid]))
			{
				$list['article']	=	$u[$aid];
			}
			else
			{
				$u[$aid] = $list[$aid] = self::_getOne($aid);
			}
		}
		else
		{
			foreach($list as &$art)
			{
				$aid	=	isset($art['aid'])?$art['aid']:$art['model_id'];
				if(isset($u[$aid]))
				{
					$art['article']	=	$u[$aid];
				}
				else
				{
					$u['article'] = $art['article'] = self::_getOne($aid);
				}
			}
		}
		
		return $list;
	}
	private static function _getOne($aid)
	{
		return Db::get('Article')->select('aid,title,pubtime')->where(array('aid'=>$aid,'del'=>0))->getOne();
	}
	
	
}